package com.nuoniu.sibanyun.controller.production;


import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.production.MaMrp;
import com.nuoniu.sibanyun.entity.production.MaMrpDetail;
import com.nuoniu.sibanyun.service.production.IMaMrpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.nuoniu.sibanyun.common.BaseController;

import java.util.List;

/**
 * <p>
 * 物料需求计划主表 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2023-05-22
 */
@RestController
@RequestMapping("/mrp/plan")
@Api(value = "生产订单管理", tags = "物料需求计划")
public class MaMrpController extends BaseController {

    @Autowired
    private IMaMrpService maMrpService;

    @ApiOperation("保存")
    @PostMapping("save")
    public HttpResult save(@RequestBody MaMrp maMrp) {
        maMrpService.saveOrder(maMrp);
        return HttpResult.ok();
    }

    @ApiOperation("获取单据编码")
    @GetMapping("getCode")
    public HttpResult getCode() {
        return HttpResult.ok(maMrpService.getCode());
    }

    @ApiOperation("删除单据")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        maMrpService.delete(id);
        return HttpResult.ok();
    }

    /**
     * 提交
     */
    @GetMapping("submit")
    @ApiOperation("单据提交")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "单据id"),
            @ApiImplicitParam(name = "status", value = "状态 0:提交,-1:反提交")
    })
    public HttpResult submit(Long id, Integer status) {
        maMrpService.submit(id, status);
        return HttpResult.ok();
    }


    @GetMapping("examine")
    @ApiOperation("单据审核")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "单据id"),
            @ApiImplicitParam(name = "status", value = "状态 0:审核,1:已审")
    })
    public HttpResult examine(Long id, Integer status) {
        maMrpService.examine(id, status);
        return HttpResult.ok();
    }

    @GetMapping("closed")
    @ApiOperation("单据开关")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "单据id"),
            @ApiImplicitParam(name = "status", value = "状态 0:关闭,1:打开")
    })
    public HttpResult closed(Long id, Integer status) {
        maMrpService.closed(id, status);
        return HttpResult.ok();
    }

    @PostMapping("merge")
    @ApiOperation("合并")
    public HttpResult merge(@RequestBody List<MaMrpDetail> maMrpDatailList) {
        maMrpService.merge(maMrpDatailList);
        return HttpResult.ok();
    }

    @PostMapping("split")
    @ApiOperation("拆分")
    public HttpResult split(@RequestBody List<MaMrpDetail> maMrpDatailList) {
        maMrpService.split(maMrpDatailList);
        return HttpResult.ok();
    }
}
